package com.nanyang.tms.manager.forecast.handler;

import com.nanyang.common.core.dict.CommonEnum;
import com.nanyang.common.core.flow.context.TransHandlerContext;
import com.nanyang.common.core.flow.handler.AbstractTransHandler;
import com.nanyang.tms.common.exception.TmsManagerException;
import com.nanyang.tms.common.util.TmsExceptionUtil;
import com.nanyang.tms.domain.forecast.context.saveforecast.SaveForecastContext;
import com.nanyang.tms.domain.waybill.shipment.context.SaveWaybillShipmentContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SendPrintTagHandler extends AbstractTransHandler{
	@Autowired
	private RocketMQTemplate rocketMQTemplate;
	@Override
	public boolean isAsync() {
		return false;
	}

	@Override
	public boolean handle(TransHandlerContext context) {
		SaveForecastContext saveForecastContext=(SaveForecastContext)context.getInnerContext(SaveForecastContext.class);
		try {
			rocketMQTemplate.asyncSend("printTag", saveForecastContext.getForecastCode(), new SendCallback() {
				@Override
				public void onSuccess(SendResult sendResult) {
					log.info(sendResult.toString());
				}
				@Override
				public void onException(Throwable e) {
					throw new TmsManagerException(CommonEnum.SYSTEM_EXCEPTION.getCode(),CommonEnum.SYSTEM_EXCEPTION.getMessage(), e);
				}
			});
		} catch (Exception e) {
			throw TmsExceptionUtil.wrapException(e);
		}
		
	
		return true;
	}

}
